<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="弹幕内容" prop="mes">
        <el-input
          v-model="queryParams.mes"
          placeholder="请输入说说内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="弹幕速度" prop="mesTime">
        <el-input
          v-model="queryParams.mesTime"
          placeholder="请输入弹幕速度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="弹幕样式" prop="mesStyle">
        <el-input
          v-model="queryParams.mesStyle"
          placeholder="请输入弹幕样式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="small"
          @click="resetQuery"
        >重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="linkList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="弹幕id" align="center" prop="id" />
      <el-table-column label="弹幕内容" align="center" prop="mes" />
      <el-table-column label="弹幕展示速度" align="center" prop="mesTime" />
      <el-table-column label="弹幕样式" align="center" prop="mesStyle" />
      <el-table-column label="弹幕头像地址" align="center" prop="mesAvatar" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <div class="changeStyle">
            <el-button
              v-hasPermission="['web:link:edit']"
              size="small"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              v-hasPermission="['web:link:remove']"
              size="small"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </div>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      :page-size.sync="queryParams.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-sizes="[10, 20, 30, 40]"
      :current-page.sync="queryParams.pageNum"
      @current-change="getList"
      @size-change="getList"
    />
  </div>
</template>

<script>
import {leaveList,delComment} from '@/api/web/leaveWord/leaveword'

export default {
  name: 'Link',
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 评论表格数据
      linkList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mes: '',
        mesTime:'',
        mesStyle:'',
      },
      // 表单参数
      form: {},

    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      leaveList(this.queryParams).then(res=>{
        this.linkList = res.records
        this.total = res.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      let queryParams1={
        pageNum: 1,
        pageSize: 10,
        KeyWord: '',
        userName:'',
        articleName:'',
      }
      this.queryParams=queryParams1
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.loading = true;
      if (this.ids.length != 0) {
        this.$confirm("是否确认删除选中的" + this.ids.length + "条留言吗？", "提示", {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delComment(this.ids).then(data => {
            this.ids = []
            this.$message.success('删除成功')
            this.loading = false;
            this.getList()
          }).catch(() => {
            this.ids = []
            this.loading = false;
          })
        }).catch(() => {
          this.ids = []
          this.loading = false;
        })
      } else {
        this.loading = false;
        this.$message.error('未选中任何数据')
      }
    }
  }
}
</script>

<style>
.changeStyle .el-button--small{
  font-size: 15px;
}
</style>
